/*
 * OMAP5 family DWC3 specific Glue layer
 *
 * Copyright (c) 2017
 * Jean-Jacques Hiblot <jjhiblot@ti.com>
 * based on dwc3-sti-glue
 *
 * SPDX-License-Identifier:	GPL-2.0+
 */

#include <common.h>
#include <dm.h>
#include <errno.h>

DECLARE_GLOBAL_DATA_PTR;

static int omap5_dwc3_glue_bind(struct udevice *dev)
{
	int dwc3_node;

	/* check if one subnode is present */
	dwc3_node = fdt_first_subnode(gd->fdt_blob, dev_of_offset(dev));
	if (dwc3_node <= 0) {
		printf("Can't find subnode for %s\n", dev->name);
		return -ENODEV;
	}
	/* check if the subnode compatible string is the dwc3 one*/
	if (fdt_node_check_compatible(gd->fdt_blob, dwc3_node,
				      "snps,dwc3") != 0) {
		printf("Can't find dwc3 subnode for %s\n", dev->name);
		return -ENODEV;
	}

	return dm_scan_fdt_dev(dev);
}

static const struct udevice_id omap5_dwc3_glue_ids[] = {
	{ .compatible = "ti,dwc3" },
	{ }
};

U_BOOT_DRIVER(dwc3_omap5_glue) = {
	.name = "dwc3_omap5_glue",
	.id = UCLASS_MISC,
	.of_match = omap5_dwc3_glue_ids,
	.bind = omap5_dwc3_glue_bind,
};
